import java.util.Scanner;

public class SmallChange1 {
    private double balance;
    private double money;
    private int choice;
    boolean flag=true;
    String note="";
    String details="说明"+"\t\t\t"+"金额"+"\t\t\t"+"余额";
    Scanner sc=new Scanner(System.in);
    public void menu() {
        System.out.println("-------零钱通明细------");
        System.out.println("1、代表收入");
        System.out.println("2、代表支出");
        System.out.println("3、带出退出");
        while (flag) {

            System.out.println("请输入你的选择：");
            choice = sc.nextInt();
            if (choice == 1) {
                this.income();


            } else if (choice == 2) {
                this.pay();

            } else if (choice == 3) {
                this.exit();

//            break;
            }

        }
    }

    public void income(){
        System.out.println("请输入收入金额：");
        money=sc.nextDouble();
        if(money>0) {
            balance += money;
            details += "\n" + "收入" + "\t\t\t" + money + "\t\t" + balance;
            System.out.println(details);
            return;
        }else{
            System.out.println("金额输入有误，请重新输入");
        }

    }
    public void pay(){
        System.out.println("请输入消费金额：");
        money=sc.nextDouble();
        if(money>0&&money<=balance) {
            System.out.println("请输入消费说明：");
            note = sc.next();
            balance -= money;
            details += "\n" + note + "\t\t\t" + money + "\t\t" + balance;
            System.out.println(details);

        }else{
            System.out.println("输入金额有误："+money+"请重新输入!");

        }
    }
    public void exit(){
        System.out.println("确定退出吗？y/n");
        String str=sc.next();
        if(str.equals("y")){
            flag=false;
            System.out.println("已退出零钱通");
        }

    }

}
